package com.sskj.login.http;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.login.bean.LoginBean;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {

    public PostRequest<HttpData> register(String account, String pswd, String invitationCode, String code, String areaCode) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER)
                .params("account", account)
                .params("pswd", pswd,true)
                .params("areaCode", account.contains("@") ? null : areaCode.replace("+",""))
                .params("invitationCode", invitationCode)
                .params("code", code);
    }


    public PostRequest<HttpData<LoginBean>> login(String areaCode, String account, String pwd, String type) {
        return OkGo.<HttpData<LoginBean>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("areaCode", account.contains("@") ? null : areaCode.replace("+",""))
                .params("account", account)
                .params("pswd",pwd,true)
                .params("systemType", type)
                ;
    }

    /**
     * 重置登录密码
     *
     * @param mobile 手机号/邮箱号
     * @param opwd   密码
     * @param code   验证码
     * @return
     */
    public PostRequest<HttpData> resetLoginPwd(String areaCode, String mobile, String opwd, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_LOGIN_PWD)
                .params("areaCode", mobile.contains("@") ? null : areaCode.replace("+",""))
                .params("account", mobile)
                .params("pswd", opwd,true)
                .params("code", code);
    }
    public PostRequest<HttpData> checkGoogle(String code, String stockUserId) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHECK_GOOGLE)
                .params("code", code)
                .params("stockUserId", stockUserId)
                ;
    }
    public GetRequest<HttpData> sendLoginSms(String account, String id, String token) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.SEND_LOGIN_SMS)
                .headers("token", token)
                .params("account", account)
                .params("id", id)
                ;
    }
}